/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package com.xuexiang.xui_lib.component.edittext.materialedittext;

/**
 * Colors
 *
 * @since 2021-03-24
 */
public class Colors {
    private static final int SIXTY = 16;
    private static final int FF = 0xFF;
    private static final int EIGHT = 8;
    private static final int ONETHREEZERO = 130;
    private static final double TWOFOURONE = .241;
    private static final double SIXNINEONE = .691;
    private static final double ZEROSIXEIGHT = .068;
    /**
     * isLight
     *
     * @param color
     * @return boolean
     */
    public static boolean isLight(int color) {
        return Math.sqrt(
                        red(color) * red(color) * TWOFOURONE
                                + green(color) * green(color) * SIXNINEONE
                                + blue(color) * blue(color) * ZEROSIXEIGHT)
                > ONETHREEZERO;
    }

    /**
     * red
     *
     * @param color
     * @return int
     */
    public static int red(int color) {
        return (color >> SIXTY) & FF;
    }

    /**
     * green
     *
     * @param color
     * @return int
     */
    public static int green(int color) {
        return (color >> EIGHT) & FF;
    }

    /**
     * blue
     *
     * @param color
     * @return int
     */
    public static int blue(int color) {
        return color & FF;
    }
}
